package com.iqiyi.pps.epg.core.service.house;

import com.iqiyi.pps.epg.core.dao.base.Page;
import com.iqiyi.pps.epg.core.dao.base.PropertyFilter;
import com.iqiyi.pps.epg.core.dao.house.HouseDao;
import com.iqiyi.pps.epg.core.model.house.House;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class HouseServiceImpl implements HouseService {
    @Autowired
    private HouseDao houseDao;

    @Override
    public House getById(Long id) {
        return houseDao.get(id);
    }

    @Override
    public List<House> getByUserId(Long userId) {
        Criterion userIdEq= Restrictions.eq("userId",userId);
        return houseDao.find(userIdEq);
    }

    @Override
    public Page<House> getPageList(Page<House> page, List<PropertyFilter> filters) {
        return houseDao.findPage(page,filters);
    }

    @Override
    public void save(House entity) {
        houseDao.save(entity);
    }

    @Override
    public void delete(Long id) {
        houseDao.delete(id);
    }
}
